package com.travel.Service.impl;


import com.travel.Service.AttractionsSearchService;
import com.travel.pojo.Attractions;
import com.travel.repo.AttractionsRepository;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.Query;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class AttractionsSearchServiceImpl implements AttractionsSearchService {

    @Resource
    AttractionsRepository attractionsRepository;

    @Override
    public Page<Attractions> search(String keyword, int pageNumber, int pageSize) {
        Query searchQuery = new NativeSearchQueryBuilder()
                .withQuery(QueryBuilders.multiMatchQuery(keyword, "name", "cname", "address"))
                .withPageable(PageRequest.of(pageNumber, pageSize))
                .build();

        return attractionsRepository.search(searchQuery);
    }
}
